About 905 letters
About 5 minutes
Description: Encapsulate a method as a static method. Refer to the classmethod function.
def staticmethod(fn):
'''
Encapsulate a method as a static method
:param fn: The method to encapsulate
:return: The encapsulated method
'''
Static methods have no implicit parameters. To declare a static method, the conventional approach is:
class C: @staticmethod def fn(arg1, arg2): pass
Example:
class Cat:
@staticmethod
def speak():
print('Meow Meow Meow')
# Call via the class
Cat.speak()
# Call via an instance
cat = Cat()
cat.speak()
Created in 5/15/2025
Updated in 5/16/2025